package com.qf.conf;

import com.alibaba.fastjson.JSON;
import com.qf.consts.Code;
import com.qf.pojo.R;
import org.springframework.security.core.Authentication;
import org.springframework.security.web.authentication.AuthenticationSuccessHandler;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

public class SuccessLoginHandler implements AuthenticationSuccessHandler {
    @Override
    public void onAuthenticationSuccess(HttpServletRequest request, HttpServletResponse response, Authentication authentication) throws IOException, ServletException {
        R r = R.success(null).putCode(Code.SUCCESS);
        String json = JSON.toJSONString(r);

        response.setContentType("application/json;charset=utf-8");
        response.getWriter().write(json);
    }
}
